import SearchTablePage from '@/components/SearchTablePage';
import { PERMISSION_KEY_LOGIN_LOG } from '@/constants';
import { getLoginLogList } from '@/services/system/log';
import { useModel } from '@umijs/max';

const LoginLog: React.FC = () => {
  const { initialState } = useModel('@@initialState');
  return (
    <>
      <SearchTablePage<API.LoginLog>
        tableName="登录日志"
        getRowsByPage={getLoginLogList}
        rowSelection={false}
        permissionKey={PERMISSION_KEY_LOGIN_LOG}
        columns={[
          {
            title: '登录日志 ID',
            dataIndex: 'id',
            hideInTable: true,
            hideInSearch: true,
          },
          {
            title: '登录用户 ID',
            dataIndex: 'loginUserId',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '登录用户名称',
            dataIndex: 'loginUser',
            showDetail: true,
          },
          {
            title: '登录类型',
            dataIndex: 'loginType',
            valueType: 'tag',
            hideInSearch: true,
            valueEnum: initialState?.system_login_type?.tagValueEnum,
          },
          {
            title: '登录 IP',
            dataIndex: 'loginIp',
          },
          {
            title: '操作系统/浏览器',
            dataIndex: 'userAgent',
            hideInSearch: true,
            hideInTable: true,
          },
          {
            title: '登录结果',
            dataIndex: 'result',
            valueType: 'tag',
            hideInSearch: true,
            valueEnum: initialState?.system_login_result?.tagValueEnum,
          },
          {
            title: '创建时间',
            dataIndex: 'createTime',
            valueType: 'dateTime',
            hideInSearch: true,
            hideInModal: true,
          },
        ]}
      />
    </>
  );
};

export default LoginLog;
